import math
import sys
import os
import re 

key_words = {}
freqs = {}
path = sys.argv[1]

num = int(re.split('[a-zA-Z.\/]+', path)[1])
	
ff = open('gen/word2nuser.txt', 'r')
fff = open('gen/user2ndocs.txt', 'r')
f = open(path, 'r')
for line in fff:
	numbers = line.split(" ")
	if int(numbers[0]) == num:
		v = int(numbers[1])
		
			

key_words = {}
freqs = {}
for line in ff:
	#print line
	list = line.split("	")
	freqs[list[0]] = int(list[1])
for line in f:
	#print line
	try:
		word_freq = line.split(" ")
		# 8503
		n11 = int(word_freq[2])
		#print n11
		n10 = int(word_freq[4]) - int(word_freq[2])
		#print n10
		n01 = v - int(word_freq[2])
		#print n01
		n00 = 8503 - int(word_freq[4]) - ( v - int(word_freq[2]))
		#print n00
		numerator = (n11+n10+n01+n00)*(n11*n00 - n10*n01)*(n11*n00 - n10*n01)
		#print numerator
		denominator = (n11+n01)*(n11+n10)*(n10+n00)*(n01+n00)
		x = numerator*1.0/denominator
		#print x
		
		key_words[word_freq[0]] = x
	except:
		pass

	
rev_key_words = dict([(val, key) for (key, val) in key_words.items()])		
for key, value in sorted(rev_key_words.items(), reverse=True):
	print value , key 
